package com.jereh.weibo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.jereh.weibo.R;
import com.jereh.weibo.adapter.MessageAdapter;
import com.jereh.weibo.entity.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/2.
 */
public class MessageFragment extends Fragment{
    private Context ctx;
    private ListView listView;
    private View headerView;
    private BaseAdapter adapter;
    private List<Message> list=new ArrayList<>();
    private int[] img={R.drawable.sina,R.mipmap.lee1,R.mipmap.gxt1};
    private String[] name={"新浪新闻","李钟硕部落","关注关晓彤"};
    private String[] neirong={"黑历史！杨幂18岁面试视频曝光！","李钟硕出演《第七次初吻》搭档李初熙。","关晓彤微博晒迪士尼游玩照！"};
    private String[] shijian={"11-05","12-04","11-28"};

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.ctx=context;

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view=inflater.inflate(R.layout.message_top,null);
        listView=(ListView)view.findViewById(R.id.listview);
        headerView=inflater.inflate(R.layout.message_top_header,null);
        adapter=new MessageAdapter(getActivity(),list);
        list.clear();
        for (int i=0;i<img.length;i++) {
            Message message = new Message();
            message.setTou(img[i]);
            message.setTitle(name[i]);
            message.setContent(neirong[i]);
            message.setTime(shijian[i]);
            list.add(message);
        }
        listView.addHeaderView(headerView);
        listView.setAdapter(adapter);
        return view;
    }
}
